#! /bin/bash
export LANG=zh_CN.UTF-8
PRESTO_HOME=/export/server/presto/bin/presto
MYSQL_HOME=/usr/bin/mysql


echo '========================================'
echo '================开始导出================='
echo '========================================'


${MYSQL_HOME} -h192.168.88.80 -p3306 -uroot -p123456 -e "
CREATE DATABASE if not exists edu_rpt DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use edu_rpt;
drop table IF EXISTS edu_rpt.kxh_rpt_day_sid_cnt;
drop table IF EXISTS edu_rpt.kxh_rpt_month_area_sid_cnt;
drop table IF EXISTS edu_rpt.kxh_rpt_month_shengfen_con_rate_cnt;
drop table IF EXISTS edu_rpt.kxh_rpt_origin_channel_sid_cnt_top;"
"

${PRESTO_HOME} --catalog hive --server 192.168.88.80:8090 --execute "
drop table IF EXISTS edu_rpt.kxh_rpt_day_sid_cnt;
create table if not exists mysql.edu_rpt.kxh_rpt_day_sid_cnt(
    create_time_day varchar comment'天',
   sid_count                bigint comment '访问用户量'
 )   comment '每日访问情况';

drop table IF EXISTS edu_rpt.kxh_rpt_month_area_sid_cnt;
create table if not exists mysql.edu_rpt.kxh_rpt_month_area_sid_cnt(
    create_time_day varchar comment'天',
     area                         varchar  comment '地域',
   sid_count               bigint comment '访问用户量'
 )   comment '每日地区用户访问量';

drop table IF EXISTS edu_rpt.kxh_rpt_month_shengfen_con_rate_cnt;
create table if not exists mysql.edu_rpt.kxh_rpt_month_shengfen_con_rate_cnt(
    create_time_day varchar comment'天',
     shengfen                 varchar  comment '省份',
     session_id_count         bigint   comment '访问Session个数',
     sid_count                bigint comment '访问用户量',
     con_rate             decimal(38,4)  comment'咨询率'
 )   comment '7月份中国各省的咨询情况';

drop table IF EXISTS edu_rpt.kxh_rpt_origin_channel_sid_cnt_top;
 create table if not exists mysql.edu_rpt.kxh_rpt_origin_channel_sid_cnt_top(
       year_month varchar comment'月',
       origin_channel   varchar   comment '投放渠道',
        sid_count     bigint comment '访问用户量'
)comment '7月份通过来源渠道访问用户量排行榜';

insert into mysql.edu_rpt.kxh_rpt_day_sid_cnt
select * from hive.edu_rpt.kxh_rpt_day_sid_cnt;

insert into mysql.edu_rpt.kxh_rpt_month_area_sid_cnt
select * from hive.edu_rpt.kxh_rpt_month_area_sid_cnt;

insert into mysql.edu_rpt.kxh_rpt_month_shengfen_con_rate_cnt
select * from hive.edu_rpt.kxh_rpt_month_shengfen_con_rate_cnt;

insert into mysql.edu_rpt.kxh_rpt_origin_channel_sid_cnt_top
select * from hive.edu_rpt.kxh_rpt_origin_channel_sid_cnt_top;
"

echo '========================================'
echo '=================success================'
echo '========================================'
